/* Janus Chat - Version 1.0
 * Authors: Matthew Perry
 *          Michael Freid
 *          Marc Latou
 *          Richard Lee
 *
 * The Janus Chat Client is a highly secured
 * peer-to-peer chat client designed to facilitate
 * the transfer of sensitive data or as a communication
 * medium for the extra paranoid
 *
 * This file contains the headers for a Unix Socket Class
 * wrapper. This will facilitate the production of janus'
 * functions. */

#ifndef SOCKET_H
#define SOCKET_H

#include "message.h"
#include <string>
#include <string.h>

//Socket libraries
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

using std::string;

class Socket
{
    private:
        string peerAddr;              /* Ip address of the destination */
        int peerPort;                 /* Port of the destination */
        int myFD;                     /* The file descriptor which identifies the socket */
        struct sockaddr_in peerInfo;  /* Struct of information on the destination */

    public:
        Socket();
        Socket( const Socket& sock ); /* Copy Constructor */
        Socket( int FD, struct sockaddr_in peer );
        Socket( int FD, struct sockaddr_in peer, struct timeval timeout );
        ~Socket() {}

        void connectTo( const string& ip, int port );
        void closeSock();
        void sendMsg( Message& msg ) const;
        Message recvMsg() const;

        int getFD() { return myFD; }
        string getAddr() { return peerAddr; }
        int getPort() { return peerPort; }
};

#endif
